package com.engine.salary.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.hrmelog.entity.dto.LoggerContext;
import com.engine.salary.config.SalaryElogConfig;
import com.engine.salary.encrypt.EncryptUtil;
import com.engine.salary.entity.siaccount.dto.InsuranceAccountViewListDTO;
import com.engine.salary.entity.siaccount.param.InsuranceAccountDetailParam;
import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailPO;
import com.engine.salary.entity.sicategory.po.ICategoryPO;
import com.engine.salary.entity.siexport.param.InsuranceExportParam;
import com.engine.salary.entity.siexport.po.AccountExportPO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
import com.engine.salary.enums.OperateTypeEnum;
import com.engine.salary.enums.siaccount.BillStatusEnum;
import com.engine.salary.enums.siaccount.PaymentStatusEnum;
import com.engine.salary.enums.siaccount.ResourceFromEnum;
import com.engine.salary.enums.sicategory.DataTypeEnum;
import com.engine.salary.enums.sicategory.PaymentScopeEnum;
import com.engine.salary.enums.sicategory.WelfareTypeEnum;
import com.engine.salary.mapper.InsuranceExportMapper;
import com.engine.salary.mapper.siaccount.InsuranceAccountDetailMapper;
import com.engine.salary.mapper.siarchives.InsuranceBaseInfoMapper;
import com.engine.salary.mapper.sicategory.ICategoryMapper;
import com.engine.salary.mapper.taxagent.TaxAgentMapper;
import com.engine.salary.service.*;
import com.engine.salary.sys.entity.po.SalarySysConfPO;
import com.engine.salary.sys.entity.vo.OrderRuleVO;
import com.engine.salary.sys.enums.OpenEnum;
import com.engine.salary.sys.service.SalarySysConfService;
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
import com.engine.salary.util.SalaryAssert;
import com.engine.salary.util.SalaryEnumUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.excel.ExcelUtil;
import com.engine.salary.util.excel.ExcelUtilPlus;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import weaver.general.BaseBean;
import weaver.hrm.User;

import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.engine.salary.enums.UserStatusEnum.getDefaultLabelByValue;
import static com.engine.salary.sys.constant.SalarySysConstant.OPEN_ACCT_RESULT_SUM;

/**
 * @Author weaver_cl
 * @Description:
 * @Date 2022/4/18
 * @Version V1.0
 **/
public class SIExportServiceImpl extends Service implements SIExportService {

    BaseBean bs = new BaseBean();

    private EncryptUtil encryptUtil = new EncryptUtil();

//    private SIAccountBiz siAccountBiz = new SIAccountBiz();

//    private SIArchivesBiz siArchivesBiz = new SIArchivesBiz();

    private SISchemeService getSISchemeService(User user) {
        return ServiceUtil.getService(SISchemeServiceImpl.class, user);
    }

    private InsuranceAccountDetailMapper getInsuranceAccountDetailMapper() {
        return MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class);
    }

    private TaxAgentMapper getTaxAgentMapper() {
        return MapperProxyFactory.getProxy(TaxAgentMapper.class);
    }

    private InsuranceExportMapper getInsuranceExportMapper() {
        return MapperProxyFactory.getProxy(InsuranceExportMapper.class);
    }

    private SalarySysConfService getSalarySysConfService(User user) {
        return  ServiceUtil.getService(SalarySysConfServiceImpl.class, user);
    }

    private InsuranceBaseInfoMapper getInsuranceBaseInfoMapper() {
        return MapperProxyFactory.getProxy(InsuranceBaseInfoMapper.class);
    }

    private TaxAgentService getTaxAgentService(User user) {
        return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
    }

    private ICategoryMapper getICategoryMapper() {
        return MapperProxyFactory.getProxy(ICategoryMapper.class);
    }

    private SIAccountService getSIAccountService(User user) {
        return ServiceUtil.getService(SIAccountServiceImpl.class, user);
    }

    public SIArchivesService getSIArchivesService(User user) {
        return ServiceUtil.getService(SIArchivesServiceImpl.class, user);
    }

    @Override
    public XSSFWorkbook exportOverView(InsuranceExportParam queryParam) {
        List<InsuranceAccountDetailPO> insuranceAccountDetailPOS = getInsuranceAccountDetailMapper().selectList(queryParam.getBillMonth(), StringUtils.isBlank(queryParam.getPaymentOrganization()) ? null : Long.valueOf(queryParam.getPaymentOrganization()));
        encryptUtil.decryptList(insuranceAccountDetailPOS, InsuranceAccountDetailPO.class);

        //获取扣缴义务人信息
        List<TaxAgentPO> paymentList =getTaxAgentMapper().listAll();
        SalaryAssert.notEmpty(paymentList, SalaryI18nUtil.getI18nLabel(100341, "该租户无扣缴义务人"));
        Map<Long, TaxAgentPO> paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgentPO::getId, Function.identity()));
//        List<InsuranceAccountViewListDTO> insuranceAccountViewListDTOS = siAccountBiz.buildRecords(insuranceAccountDetailPOS, paymentMap);
        List<InsuranceAccountViewListDTO> insuranceAccountViewListDTOS = getSIAccountService(user).buildRecords(insuranceAccountDetailPOS, paymentMap);

        List<List<Object>> excelSheetData = new ArrayList<>();
        // 1.工作簿名称
        String sheetName = SalaryI18nUtil.getI18nLabel(85368, "社保福利档案");
        // 2.表头
        String[] header = {
                SalaryI18nUtil.getI18nLabel(93270, "个税扣缴义务人"),
                SalaryI18nUtil.getI18nLabel(93272, "社保人数"),
                SalaryI18nUtil.getI18nLabel(93273, "公积金人数"),
                SalaryI18nUtil.getI18nLabel(93274, "其他福利人数"),
                SalaryI18nUtil.getI18nLabel(93275, "社保缴费合计"),
                SalaryI18nUtil.getI18nLabel(93276, "公积金缴费合计"),
                SalaryI18nUtil.getI18nLabel(93277, "其他福利缴费合计"),
                SalaryI18nUtil.getI18nLabel(93278, "合计")};
        excelSheetData.add(Arrays.asList(header));

        //工作簿数据
        List<List<Object>> rows = new LinkedList<>();
        for (InsuranceAccountViewListDTO dto : insuranceAccountViewListDTOS) {
            List<Object> row = new LinkedList<>();
            row.add(dto.getPayOrg());
            row.add(dto.getSocialNum());
            row.add(dto.getFundNum());
            row.add(dto.getOtherNum());
            row.add(dto.getSocialPaySum());
            row.add(dto.getFundPaySum());
            row.add(dto.getOtherPaySum());
            row.add(dto.getSum());
            rows.add(row);
        }
        excelSheetData.addAll(rows);
        //记录操作日志
        LoggerContext loggerContext = new LoggerContext<>();
        loggerContext.setUser(user);
        loggerContext.setOperateType(OperateTypeEnum.EXCEL_EXPORT.getValue());
        loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(0, "福利台账-导出总览"));
        loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(0, "福利台账-导出总览"));
        SalaryElogConfig.siAccountLoggerTemplate.write(loggerContext);
        return ExcelUtil.genWorkbookV2(excelSheetData, sheetName);
    }

    @Override
    public XSSFWorkbook exportAccount(Integer paymentStatus, InsuranceExportParam param) {

        //排序配置
        OrderRuleVO orderRule = getSalarySysConfService(user).orderRule();
        param.setOrderRule(orderRule);

        List<AccountExportPO> accountExportPOS = new ArrayList<>();
        if (paymentStatus.equals(PaymentStatusEnum.RECESSION.getValue())) {
            accountExportPOS = getInsuranceExportMapper().exportRecessionAccount(paymentStatus, param);
            //非系统人员核算明细
            List<AccountExportPO> extAccountExportPOS = getInsuranceExportMapper().exportExtAccount(paymentStatus, param);
            accountExportPOS.addAll(extAccountExportPOS);
        } else {
            accountExportPOS = getInsuranceExportMapper().exportAccount(paymentStatus, param);
            //非系统人员核算明细
            List<AccountExportPO> extAccountExportPOS = getInsuranceExportMapper().exportExtAccount(paymentStatus, param);
            accountExportPOS.addAll(extAccountExportPOS);
        }

//        //过滤出福利档案基础信息表中runStatus为正在缴纳和待减员的人员
//        if (!paymentStatus.equals(PaymentStatusEnum.RECESSION.getValue())) {
//            List<InsuranceArchivesBaseInfoPO> baseInfoPOList = getInsuranceBaseInfoMapper().listAll();
//            List<Long> canAccountIds = baseInfoPOList.stream()
//                    .filter(f->f.getPaymentOrganization().toString().equals(param.getPaymentOrganization())
//                            && (f.getRunStatus().equals(EmployeeStatusEnum.PAYING.getValue()) || f.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue())))
//                    .map(InsuranceArchivesBaseInfoPO::getEmployeeId)
//                    .collect(Collectors.toList());
//            accountExportPOS = accountExportPOS.stream().filter(f -> canAccountIds.contains(f.getEmployeeId())).collect(Collectors.toList());
//        }

        encryptUtil.decryptList(accountExportPOS, AccountExportPO.class);
        SalaryI18nUtil.i18nList(accountExportPOS);
        List<WeaTableColumn> columns = new ArrayList<>();
        List<Map<String, Object>> records = new ArrayList<>();
//        if (Objects.equals(PaymentStatusEnum.COMMON.getValue(), paymentStatus)) {
//            columns = buildCommonColumns(accountExportPOS, false);
//        }
//        if (Objects.equals(PaymentStatusEnum.REPAIR.getValue(), paymentStatus)) {
//            columns = buildCommonColumns(accountExportPOS, true);
//        }
        columns = buildCommonColumns(accountExportPOS, paymentStatus);

        records = buildCommonRecords(accountExportPOS, false);
        List<List<Object>> excelSheetData = new ArrayList<>();
        //工作簿名称
        String sheetName = SalaryI18nUtil.getI18nLabel(0, "社保福利台账");
        excelSheetData.add(Arrays.asList(columns.stream().map(WeaTableColumn::getText).toArray(String[]::new)));
        //合计
        boolean total = false;
        SalarySysConfPO openSum = getSalarySysConfService(user).getOneByCode(OPEN_ACCT_RESULT_SUM);
        if (openSum != null && StringUtils.isNotBlank(openSum.getConfValue()) && OpenEnum.parseByValue(openSum.getConfValue()) == OpenEnum.OPEN) {
            total = true;
            InsuranceAccountDetailParam queryParam = new InsuranceAccountDetailParam();
            BeanUtils.copyProperties(param, queryParam);
            Map<String, Object> sumRow = new HashMap<>();
            if (paymentStatus.equals(PaymentStatusEnum.COMMON.getValue())) {
                sumRow = getSIAccountService(user).listCommonSum(queryParam);
            } else if (paymentStatus.equals(PaymentStatusEnum.REPAIR.getValue())) {
                sumRow = getSIAccountService(user).listSupplementarySum(queryParam);
            } else if (paymentStatus.equals(PaymentStatusEnum.RECESSION.getValue())) {
                sumRow = getSIAccountService(user).listRecessionSum(queryParam);
            } else if (paymentStatus.equals(PaymentStatusEnum.BALANCE.getValue())) {
                sumRow = getSIAccountService(user).listBalanceSum(queryParam);
            }
            Map<String, Object> sumMap = (Map<String, Object>) sumRow.get("sumRow");
            sumMap.put("department", "总计");

            records.add(sumMap);
        }
        //工作簿数据
        List<List<Object>> rows = new LinkedList<>();
        for (Map<String, Object> recordData : records) {
            List<Object> row = new LinkedList<>();
            for (WeaTableColumn column : columns) {
                try {
                    if (column.getText().contains("个人") || column.getText().contains("单位") || column.getText().contains("合计")) {
                        row.add(new BigDecimal(recordData.get(column.getColumn()).toString()));
                    } else {
                        row.add(recordData.get(column.getColumn()));
                    }
                } catch (Exception e) {
                    row.add(recordData.get(column.getColumn()));
                }
            }
            rows.add(row);
        }

        excelSheetData.addAll(rows);
        //记录操作日志
        PaymentStatusEnum targetEnum = SalaryEnumUtil.enumMatchByValue(paymentStatus, PaymentStatusEnum.values(), PaymentStatusEnum.class);
        LoggerContext loggerContext = new LoggerContext<>();
        loggerContext.setUser(user);
        loggerContext.setOperateType(OperateTypeEnum.EXCEL_EXPORT.getValue());
        loggerContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(0, "福利台账明细表-导出")
                + SalaryI18nUtil.getI18nLabel(targetEnum.getLabelId(), targetEnum.getDefaultLabel()));
        loggerContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(0, "福利台账明细表-导出")
                + SalaryI18nUtil.getI18nLabel(targetEnum.getLabelId(), targetEnum.getDefaultLabel()));
        SalaryElogConfig.siAccountLoggerTemplate.write(loggerContext);
        return ExcelUtilPlus.genWorkbookV2(excelSheetData, sheetName, total);
    }

    @Override
    public List<Map<String, Object>> buildCommonRecords(List<AccountExportPO> list, boolean isExport) {
//        boolean welBaseDiffSign = siArchivesBiz.isDiffWelBase();
        boolean welBaseDiffSign = getSIArchivesService(user).isDiffWelBase();
        List<Map<String, Object>> result = new ArrayList<>();

        List<TaxAgentPO> paymentList = getTaxAgentMapper().listAll();
        SalaryAssert.notEmpty(paymentList, SalaryI18nUtil.getI18nLabel(100341, "该租户无扣缴义务人"));
        Map<Long, String> schemeIdNameMap = getSISchemeService(user).getSchemeIdNameMap();
        Map<Long, TaxAgentPO> paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgentPO::getId, Function.identity()));
        list.forEach(item -> {
            Map<String, Object> record = new HashMap<>();
            record.put("billMonth", item.getBillMonth());
            record.put("billStatus", SalaryEnumUtil.enumMatchByValue(item.getBillStatus(), BillStatusEnum.values(), BillStatusEnum.class));
            record.put("userName", item.getUserName());
            if (isExport) {
                record.put("department", item.getDepartmentName());
                record.put("employeeStatus", item.getUserStatus() == null ? "" : getDefaultLabelByValue(item.getUserStatus()));
            } else {
                record.put("department", item.getFixedDepartmentName());
                record.put("employeeStatus", item.getFixedUserStatus() == null ? "" : getDefaultLabelByValue(item.getFixedUserStatus()));
            }
            record.put("supplementaryMonth", item.getSupplementaryMonth());
            record.put("mobile", item.getTelephone());
            record.put("workcode", item.getWorkcode());
            record.put("idNo", item.getIdNo());
            ResourceFromEnum from = SalaryEnumUtil.enumMatchByValue(item.getResourceFrom(), ResourceFromEnum.values(), ResourceFromEnum.class);
            record.put("sourceFrom", SalaryI18nUtil.getI18nLabel(from.getLabelId(), from.getDefaultLabel()));

            record.put("socialPayOrg", paymentMap.get(item.getPaymentOrganization()) == null ? "" : paymentMap.get(item.getPaymentOrganization()).getName());

            record.put("socialAccount", item.getSocialAccount());
            record.put("socialSchemeName", schemeIdNameMap.get(item.getSocialSchemeId()));
            if (StringUtils.isNotEmpty(item.getSocialPaymentBaseString())) {
                Map<String, Object> socialJson = JSON.parseObject(item.getSocialPaymentBaseString(), new HashMap<String, Object>().getClass());
//                if (socialJson != null) {
//                    socialJson.forEach((k, v) -> {
//                        record.put(k + "socialBase", v);
//                    });
//                }
                if (welBaseDiffSign) {
                    if (socialJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getSocialSchemeId(), PaymentScopeEnum.SCOPE_PERSON.getValue());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getSocialSchemeId(), PaymentScopeEnum.SCOPE_PERSON.getValue());
                        socialJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "socialPerBase", v);
                            }
                        });
                    }
                    Map<String, Object> socialComJson = JSON.parseObject(item.getSocialPaymentComBaseString(), new TypeReference<Map<String, Object>>() {
                    });
                    if (socialComJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getSocialSchemeId(),PaymentScopeEnum.SCOPE_COMPANY.getValue());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getSocialSchemeId(),PaymentScopeEnum.SCOPE_COMPANY.getValue());
                        socialComJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "socialComBase", v);
                            }
                        });
                    }
                } else {
                    if (socialJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getSocialSchemeId());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getSocialSchemeId());
                        socialJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "socialBase", v);
                            }
                        });
                    }
                }

            }
            record.put("fundPayOrg", paymentMap.get(item.getSocialPayOrg()) == null ? "" : paymentMap.get(item.getSocialPayOrg()).getName());
            record.put("fundAccount", item.getFundAccount());
            record.put("fundSchemeName", schemeIdNameMap.get(item.getFundSchemeId()));
            record.put("supplementFundAccount", item.getSupplementFundAccount());
            if (StringUtils.isNotEmpty(item.getFundPaymentBaseString())) {
                Map<String, Object> fundJson = JSON.parseObject(item.getFundPaymentBaseString(), new HashMap<String, Object>().getClass());
//                if (fundJson != null) {
//                    fundJson.forEach((k, v) -> {
//                        record.put(k + "fundBase", v);
//                    });
//                }
                if (welBaseDiffSign) {
                    if (fundJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getFundSchemeId(),PaymentScopeEnum.SCOPE_PERSON.getValue());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getFundSchemeId(),PaymentScopeEnum.SCOPE_PERSON.getValue());
                        fundJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "fundPerBase", v);
                            }
                        });
                    }
                    Map<String, Object> fundComJson = JSON.parseObject(item.getFundPaymentComBaseString(), new TypeReference<Map<String, Object>>() {
                    });
                    if (fundComJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getFundSchemeId(),PaymentScopeEnum.SCOPE_COMPANY.getValue());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getFundSchemeId(),PaymentScopeEnum.SCOPE_COMPANY.getValue());
                        fundComJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "fundComBase", v);
                            }
                        });
                    }
                } else {
                    if (fundJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getFundSchemeId());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getFundSchemeId());
                        fundJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "fundBase", v);
                            }
                        });
                    }
                }

            }
            record.put("otherPayOrg", paymentMap.get(item.getOtherPayOrg()) == null ? "" : paymentMap.get(item.getOtherPayOrg()).getName());
            record.put("otherSchemeName", schemeIdNameMap.get(item.getOtherSchemeId()));
            if (StringUtils.isNotEmpty(item.getOtherPaymentBaseString())) {
                Map<String, Object> otherJson = JSON.parseObject(item.getOtherPaymentBaseString(), new HashMap<String, Object>().getClass());
//                if (otherJson != null) {
//                    otherJson.forEach((k, v) -> {
//                        record.put(k + "otherBase", v);
//                    });
//                }
                if (welBaseDiffSign) {
                    if (otherJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getOtherSchemeId(),PaymentScopeEnum.SCOPE_PERSON.getValue());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getOtherSchemeId(),PaymentScopeEnum.SCOPE_PERSON.getValue());
                        otherJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "otherPerBase", v);
                            }
                        });
                    }
                    Map<String, Object> otherComJson = JSON.parseObject(item.getOtherPaymentComBaseString(), new TypeReference<Map<String, Object>>() {
                    });
                    if (otherComJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getOtherSchemeId(),PaymentScopeEnum.SCOPE_COMPANY.getValue());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getOtherSchemeId(),PaymentScopeEnum.SCOPE_COMPANY.getValue());
                        otherComJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "otherComBase", v);
                            }
                        });
                    }
                } else {
                    if (otherJson != null) {
                        //查询该福利方案下开启缴纳的福利项
//                        List<Long> insuranceIdList = siArchivesBiz.payInsuranceIds(item.getOtherSchemeId());
                        List<Long> insuranceIdList = getSIArchivesService(user).payInsuranceIds(item.getOtherSchemeId());
                        otherJson.forEach((k, v) -> {
                            if (insuranceIdList.contains(Long.valueOf(k))) {
                                record.put(k + "otherBase", v);
                            }
                        });
                    }
                }

            }
            if (StringUtils.isNotEmpty(item.getSocialPerJson())) {
                Map<String, Object> socialJson = JSON.parseObject(item.getSocialPerJson(), new HashMap<String, Object>().getClass());
                if (socialJson != null) {
                    socialJson.forEach((k, v) -> {
                        record.put(k + "socialPer", v);
                    });
                }

            }
            record.put("socialPerSum", item.getSocialPerSum());
            if (StringUtils.isNotEmpty(item.getFundPerJson())) {
                Map<String, Object> fundPerJson = JSON.parseObject(item.getFundPerJson(), new HashMap<String, Object>().getClass());
                if (fundPerJson != null) {
                    fundPerJson.forEach((k, v) -> {
                        record.put(k + "fundPer", v);
                    });
                }

            }
            record.put("fundPerSum", item.getFundPerSum());
            if (StringUtils.isNotEmpty(item.getOtherPerJson())) {
                Map<String, Object> fundPerJson = JSON.parseObject(item.getOtherPerJson(), new HashMap<String, Object>().getClass());
                if (fundPerJson != null) {
                    fundPerJson.forEach((k, v) -> {
                        record.put(k + "otherPer", v);
                    });
                }

            }
            record.put("otherPerSum", item.getOtherPerSum());
            record.put("perSum", item.getPerSum());
            if (StringUtils.isNotEmpty(item.getSocialComJson())) {
                Map<String, Object> fundPerJson = JSON.parseObject(item.getSocialComJson(), new HashMap<String, Object>().getClass());
                if (fundPerJson != null) {
                    fundPerJson.forEach((k, v) -> {
                        record.put(k + "socialCom", v);
                    });
                }

            }
            record.put("socialComSum", item.getSocialComSum());
            if (StringUtils.isNotEmpty(item.getFundComJson())) {
                Map<String, Object> fundPerJson = JSON.parseObject(item.getFundComJson(), new HashMap<String, Object>().getClass());
                if (fundPerJson != null) {
                    fundPerJson.forEach((k, v) -> {
                        record.put(k + "fundCom", v);
                    });
                }

            }
            record.put("fundComSum", item.getFundComSum());
            if (StringUtils.isNotEmpty(item.getOtherPerJson())) {
                Map<String, Object> fundPerJson = JSON.parseObject(item.getOtherComJson(), new HashMap<String, Object>().getClass());
                if (fundPerJson != null) {
                    fundPerJson.forEach((k, v) -> {
                        record.put(k + "otherCom", v);
                    });
                }

            }
            record.put("otherComSum", item.getOtherComSum());
            record.put("comSum", item.getComSum());
            record.put("socialSum", item.getSocialSum());
            record.put("fundSum", item.getFundSum());
            record.put("otherSum", item.getOtherSum());
            record.put("total", item.getTotal());
            result.add(record);
        });
        return result;
    }

    private Map<Integer, Map<String, String>> buildComTitle(List<AccountExportPO> pos, Map<String, String> categoryIdNameMap) {
        Set<String> socailIds = new HashSet<>();
        Set<String> fundIds = new HashSet<>();
        Set<String> otherIds = new HashSet<>();
        Map<Integer, Map<String, String>> result = new HashMap<>();

        pos.stream().forEach(item -> {
            if (StringUtils.isNotBlank(item.getSocialComJson())) {
                Map<String, String> socialJson = JSON.parseObject(item.getSocialComJson(), new HashMap<String, String>().getClass());
                if (socialJson != null) {
                    socialJson.forEach((k, v) -> {
                        socailIds.add(k);
                    });
                }

            }
            if (StringUtils.isNotBlank(item.getFundComJson())) {
                Map<String, String> fundJson = JSON.parseObject(item.getFundComJson(), new HashMap<String, String>().getClass());
                if (fundJson != null) {
                    fundJson.forEach((k, v) -> {
                        fundIds.add(k);
                    });
                }

            }
            if (StringUtils.isNotBlank(item.getOtherComJson())) {
                Map<String, String> otherJson = JSON.parseObject(item.getOtherComJson(), new HashMap<String, String>().getClass());
                if (otherJson != null) {
                    otherJson.forEach((k, v) -> {
                        otherIds.add(k);
                    });
                }

            }
        });
        Map<String, String> socialColumns = new HashMap<>();
        Map<String, String> fundColumns = new HashMap<>();
        Map<String, String> otherColumns = new HashMap<>();
        socailIds.stream().forEach(social -> {
            if (categoryIdNameMap.containsKey(social)) {
                socialColumns.put(
                        categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(100289, "单位"),
                        social + "socialCom");
            }
        });
        fundIds.stream().forEach(social -> {
            if (categoryIdNameMap.containsKey(social)) {
                fundColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(100289, "单位"),
                        social + "fundCom");
            }
        });
        otherIds.stream().forEach(social -> {
            if (categoryIdNameMap.containsKey(social)) {
                otherColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(100289, "单位"),
                        social + "otherCom");
            }
        });
        // map根据value排序
        LinkedHashMap<String, String> socialColumnsWithAscValue = socialColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));
        LinkedHashMap<String, String> fundColumnsWithAscValue = fundColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));
        LinkedHashMap<String, String> otherColumnsWithAscValue = otherColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));

        result.put(WelfareTypeEnum.SOCIAL_SECURITY.getValue(), socialColumnsWithAscValue);
        result.put(WelfareTypeEnum.ACCUMULATION_FUND.getValue(), fundColumnsWithAscValue);
        result.put(WelfareTypeEnum.OTHER.getValue(), otherColumnsWithAscValue);
        return result;
    }

    private Map<Integer, Map<String, String>> buildPersonalTitle(List<AccountExportPO> pos, Map<String, String> categoryIdNameMap) {
        Set<String> socailIds = new HashSet<>();
        Set<String> fundIds = new HashSet<>();
        Set<String> otherIds = new HashSet<>();
        Map<Integer, Map<String, String>> result = new HashMap<>();

        pos.stream().forEach(item -> {
            if (StringUtils.isNotBlank(item.getSocialPerJson())) {
                Map<String, String> socialJson = JSON.parseObject(item.getSocialPerJson(), new HashMap<String, String>().getClass());
                if (socialJson != null) {
                    socialJson.forEach((k, v) -> {
                        socailIds.add(k);
                    });
                }

            }
            if (StringUtils.isNotBlank(item.getFundPerJson())) {
                Map<String, String> fundJson = JSON.parseObject(item.getFundPerJson(), new HashMap<String, String>().getClass());
                if (fundJson != null) {
                    fundJson.forEach((k, v) -> {
                        fundIds.add(k);
                    });
                }

            }
            if (StringUtils.isNotBlank(item.getOtherPerJson())) {
                Map<String, String> otherJson = JSON.parseObject(item.getOtherPerJson(), new HashMap<String, String>().getClass());
                if (otherJson != null) {
                    otherJson.forEach((k, v) -> {
                        otherIds.add(k);
                    });
                }

            }
        });
        Map<String, String> socialColumns = new HashMap<>();
        Map<String, String> fundColumns = new HashMap<>();
        Map<String, String> otherColumns = new HashMap<>();
        socailIds.stream().forEach(social -> {
            if (categoryIdNameMap.containsKey(social)) {
                socialColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(87159, "个人"),
                        social + "socialPer");
            }
        });
        fundIds.stream().forEach(social -> {
            if (categoryIdNameMap.containsKey(social)) {
                fundColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(87159, "个人"),
                        social + "fundPer");
            }
        });
        otherIds.stream().forEach(social -> {
            if (categoryIdNameMap.containsKey(social)) {
                otherColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(87159, "个人"),
                        social + "otherPer");
            }
        });
        // map根据value排序
        LinkedHashMap<String, String> socialColumnsWithAscValue = socialColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));
        LinkedHashMap<String, String> fundColumnsWithAscValue = fundColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));
        LinkedHashMap<String, String> otherColumnsWithAscValue = otherColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));

        result.put(WelfareTypeEnum.SOCIAL_SECURITY.getValue(), socialColumnsWithAscValue);
        result.put(WelfareTypeEnum.ACCUMULATION_FUND.getValue(), fundColumnsWithAscValue);
        result.put(WelfareTypeEnum.OTHER.getValue(), otherColumnsWithAscValue);
        return result;
    }


    private List<WeaTableColumn> buildCommonColumns(List<AccountExportPO> pos, Integer paymentStatus) {
        List<WeaTableColumn> list = new ArrayList<>();
        Map<String, String> categoryIdNameMap = categoryIdNameMap();
        Map<Integer, Map<String, String>> columns = buildPaymentTitle(pos, categoryIdNameMap);
        Map<Integer, Map<String, String>> personColumns = buildPersonalTitle(pos, categoryIdNameMap);
        Map<Integer, Map<String, String>> comColumns = buildComTitle(pos, categoryIdNameMap);
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(85429, "姓名"), "userName"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(86185, "部门"), "department"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(86186, "手机号"), "mobile"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(86317, "工号"), "workcode"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(86187, "员工状态"), "employeeStatus"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(86187, "证件号码"), "idNo"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100377, "数据来源"), "sourceFrom"));
        if (paymentStatus.equals(PaymentStatusEnum.REPAIR.getValue())) {
            list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100379, "补缴月份"), "supplementaryMonth"));
        } else if (paymentStatus.equals(PaymentStatusEnum.RECESSION.getValue())) {
            list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100379, "退差月份"), "supplementaryMonth"));
        }
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(91325, "个税扣缴义务人"), "socialPayOrg"));
        if (!paymentStatus.equals(PaymentStatusEnum.BALANCE.getValue())) {
            list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(91324, "社保账号"), "socialAccount"));
            list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(91323, "社保方案名称"), "socialSchemeName"));
        }

        //组装社保基数
        columns.get(WelfareTypeEnum.SOCIAL_SECURITY.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });

        if (!paymentStatus.equals(PaymentStatusEnum.BALANCE.getValue())) {
            list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(91486, "公积金账号"), "fundAccount"));
            list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(91485, "公积金方案名称"), "fundSchemeName"));
        }

        //组装公积金基数
        columns.get(WelfareTypeEnum.ACCUMULATION_FUND.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });
        if (!paymentStatus.equals(PaymentStatusEnum.BALANCE.getValue())) {
            list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(91487, "补充公积金账号"), "supplementFundAccount"));
            list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(91496, "其他福利方案名称"), "otherSchemeName"));
        }

        columns.get(WelfareTypeEnum.OTHER.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });
        personColumns.get(WelfareTypeEnum.SOCIAL_SECURITY.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100388, "社保个人合计"), "socialPerSum"));
        personColumns.get(WelfareTypeEnum.ACCUMULATION_FUND.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100390, "公积金个人合计"), "fundPerSum"));
        personColumns.get(WelfareTypeEnum.OTHER.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100392, "其他福利个人合计"), "otherPerSum"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100393, "个人合计"), "perSum"));
        comColumns.get(WelfareTypeEnum.SOCIAL_SECURITY.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100394, "社保单位合计"), "socialComSum"));
        comColumns.get(WelfareTypeEnum.ACCUMULATION_FUND.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100395, "公积金单位合计"), "fundComSum"));
        comColumns.get(WelfareTypeEnum.OTHER.getValue()).forEach((k, v) -> {
            list.add(new WeaTableColumn("150px", k, v));
        });
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100396, "其他福利单位合计"), "otherComSum"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100397, "单位合计"), "comSum"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100398, "社保合计"), "socialSum"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100399, "公积金合计"), "fundSum"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(100400, "其他福利合计"), "otherSum"));
        list.add(new WeaTableColumn("150px", SalaryI18nUtil.getI18nLabel(93278, "合计"), "total"));
        return list;
    }

    private Map<String, String> categoryIdNameMap() {
        //系统福利类型
        Map<Long, String> systemMap = getICategoryMapper().listByDataType(DataTypeEnum.SYSTEM.getValue()).stream()
                .collect(Collectors.toMap(ICategoryPO::getId, ICategoryPO::getInsuranceName));
        Map<Long, String> customMap = getICategoryMapper().listAll()
                .stream().collect(Collectors.toMap(ICategoryPO::getId, ICategoryPO::getInsuranceName));
        HashMap<Long, String> total = new HashMap<>();
        if (MapUtils.isNotEmpty(systemMap)) {
            total.putAll(systemMap);
        }
        if (MapUtils.isNotEmpty(customMap)) {
            total.putAll(customMap);
        }
        HashMap<String, String> result = new HashMap<>();
        total.forEach((k, v) -> {
            result.put(String.valueOf(k), v);
        });

        return result;
    }

    private Map<Integer, Map<String, String>> buildPaymentTitle(List<AccountExportPO> pos, Map<String, String> categoryIdNameMap) {
//        boolean welBaseDiffSign = siArchivesBiz.isDiffWelBase();
        boolean welBaseDiffSign = getSIArchivesService(user).isDiffWelBase();
        Set<String> socailIds = new HashSet<>();
        Set<String> fundIds = new HashSet<>();
        Set<String> otherIds = new HashSet<>();

        Set<String> socailComIds = new HashSet<>();
        Set<String> fundComIds = new HashSet<>();
        Set<String> otherComIds = new HashSet<>();

        Map<Integer, Map<String, String>> result = new HashMap<>();

        pos.stream().forEach(item -> {
            if (StringUtils.isNotBlank(item.getSocialPaymentBaseString()) || StringUtils.isNotBlank(item.getSocialPaymentComBaseString())) {
                Map<String, String> socialJson = JSON.parseObject(item.getSocialPaymentBaseString(), new HashMap<String, String>().getClass());
                if (socialJson != null) {
                    socialJson.forEach((k, v) -> {
                        socailIds.add(k);
                    });
                }
                //如果需要区分个人和公司福利基数
                if (welBaseDiffSign) {
                    Map<String, Object> socialComJson = JSON.parseObject(item.getSocialPaymentComBaseString(), new TypeReference<Map<String, Object>>() {
                    });
                    if (socialComJson != null) {
                        socialComJson.forEach((k, v) -> socailComIds.add(k));
                    }
                }

            }
            if (StringUtils.isNotBlank(item.getFundPaymentBaseString()) || StringUtils.isNotBlank(item.getFundPaymentComBaseString())) {
                Map<String, String> fundJson = JSON.parseObject(item.getFundPaymentBaseString(), new HashMap<String, String>().getClass());
                if (fundJson != null) {
                    fundJson.forEach((k, v) -> {
                        fundIds.add(k);
                    });
                }
                //如果需要区分个人和公司福利基数
                if (welBaseDiffSign) {
                    Map<String, Object> fundComJson = JSON.parseObject(item.getFundPaymentComBaseString(), new TypeReference<Map<String, Object>>() {
                    });
                    if (fundComJson != null) {
                        fundComJson.forEach((k, v) -> fundComIds.add(k));
                    }
                }

            }
            if (StringUtils.isNotBlank(item.getOtherPaymentBaseString()) || StringUtils.isNotBlank(item.getOtherPaymentComBaseString())) {
                Map<String, String> otherJson = JSON.parseObject(item.getOtherPaymentBaseString(), new HashMap<String, String>().getClass());
                if (otherJson != null) {
                    otherJson.forEach((k, v) -> {
                        otherIds.add(k);
                    });
                }
                //如果需要区分个人和公司福利基数
                if (welBaseDiffSign) {
                    Map<String, Object> otherComJson = JSON.parseObject(item.getOtherPaymentComBaseString(), new TypeReference<Map<String, Object>>() {
                    });
                    if (otherComJson != null) {
                        otherComJson.forEach((k, v) -> otherComIds.add(k));
                    }
                }

            }
        });
        Map<String, String> socialColumns = new HashMap<>();
        Map<String, String> fundColumns = new HashMap<>();
        Map<String, String> otherColumns = new HashMap<>();

        Map<String, String> socialComColumns = new HashMap<>();
        Map<String, String> fundComColumns = new HashMap<>();
        Map<String, String> otherComColumns = new HashMap<>();

        if (welBaseDiffSign) {
            socailIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    socialColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(0, "申报基数") + SalaryI18nUtil.getI18nLabel( 0, "个人"), social + "socialPerBase");
                }
            });
            fundIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    fundColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 0, "申报基数") + SalaryI18nUtil.getI18nLabel( 0, "个人"), social + "fundPerBase");
                }
            });
            otherIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    otherColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 0, "申报基数") + SalaryI18nUtil.getI18nLabel( 0, "个人"), social + "otherPerBase");
                }
            });

            socailComIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    socialComColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(0, "申报基数") + SalaryI18nUtil.getI18nLabel( 0, "单位"), social + "socialComBase");
                }
            });
            fundComIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    fundComColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 0, "申报基数") + SalaryI18nUtil.getI18nLabel( 0, "单位"), social + "fundComBase");
                }
            });
            otherComIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    otherComColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 0, "申报基数") + SalaryI18nUtil.getI18nLabel( 0, "单位"), social + "otherComBase");
                }
            });
        } else {
            socailIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    socialColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel(0, "申报基数"), social + "socialBase");
                }
            });
            fundIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    fundColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 0, "申报基数"), social + "fundBase");
                }
            });
            otherIds.stream().forEach(social -> {
                if (categoryIdNameMap.containsKey(social)) {
                    otherColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 0, "申报基数"), social + "otherBase");
                }
            });
        }
        // map根据value排序
        LinkedHashMap<String, String> socialColumnsWithAscValue = socialColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));
        LinkedHashMap<String, String> fundColumnsWithAscValue = fundColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));
        LinkedHashMap<String, String> otherColumnsWithAscValue = otherColumns.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                        LinkedHashMap::new));

        if (welBaseDiffSign) {
            LinkedHashMap<String, String> socialComMapWithAscKey = socialComColumns.entrySet().stream()
                    .sorted(Map.Entry.comparingByKey())
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                            LinkedHashMap::new));
            LinkedHashMap<String, String> fundComMapWithAscKey = fundComColumns.entrySet().stream()
                    .sorted(Map.Entry.comparingByKey())
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                            LinkedHashMap::new));
            LinkedHashMap<String, String> otherComMapWithAscKey = otherComColumns.entrySet().stream()
                    .sorted(Map.Entry.comparingByKey())
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue,
                            LinkedHashMap::new));
            socialColumnsWithAscValue.putAll(socialComMapWithAscKey);
            fundColumnsWithAscValue.putAll(fundComMapWithAscKey);
            otherColumnsWithAscValue.putAll(otherComMapWithAscKey);
        }

        result.put(WelfareTypeEnum.SOCIAL_SECURITY.getValue(), socialColumnsWithAscValue);
        result.put(WelfareTypeEnum.ACCUMULATION_FUND.getValue(), fundColumnsWithAscValue);
        result.put(WelfareTypeEnum.OTHER.getValue(), otherColumnsWithAscValue);
        return result;
    }
}

